import { findKey } from '../core/findKey'
import { findIdx } from '../core/findIdx'
import { isArrLike } from '../core/isArrLike'
import { isUndef } from '../core/isUndef'
//11472
/**
 * 类似es6 Array中的find方法
 *  example
         * find(
         *     [
         *         {
         *             name: 'john',
         *             age: 24
         *         },
         *         {
         *             name: 'jane',
         *             age: 23
         *         }
         *     ],
         *     function(val) {
         *         return val.age === 23;
         *     }
         * ); // -> {name: 'jane', age: 23}
dependencies  findKey findIdx isArrLike isUndef
 * @param {*} obj 
 * @param {*} predicate 
 * @param {*} ctx 
 * @returns 
 */
export function find (obj, predicate, ctx) {
  var keyFinder = isArrLike(obj) ? findIdx : findKey;
  var key = keyFinder(obj, predicate, ctx);
  if (!isUndef(key) && key !== -1) return obj[key];
}